//
//  GSArticleADView.m
//  GameSky
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSArticleADView.h"
#define kMargin 10

@implementation GSArticleADView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        self.coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(kMargin, kMargin, 80, 80)];
        [self addSubview:self.coverImage];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.coverImage.right + kMargin, self.coverImage.top, kWidth - kMargin * 4 - self.coverImage.width - 30, 30)];
        self.titleLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:self.titleLabel];
        
        self.descLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.titleLabel.bottom + kMargin, kWidth - kMargin * 3 - self.coverImage.width, 40)];
        self.descLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
        self.descLabel.font = [UIFont systemFontOfSize:12];
        self.descLabel.numberOfLines = 0;
        [self addSubview:self.descLabel];
        
        UIImageView *promImage = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth - kMargin - 31, kMargin, 31, 17)];
        promImage.image = [UIImage imageNamed:@"common_Badge_TuiGuang_31x17_UIMode_Day"];
        [self addSubview:promImage];
    }
    return self;
}

- (void)setModel:(GSNewsADModel *)model {
    _model = model;
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:model.icon1] placeholderImage:kPHImage];
    self.titleLabel.text = model.title1;
    self.descLabel.text = model.shortTitle1;
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_model.link1]];
}

@end
